//
//  WatchViewCell.m
//  Courses
//
//  Created by YiXuePxh on 15/4/14.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "WatchViewCell.h"

#import "UIImageView+WebCache.h"
#import "CourseClass.h"
#import "NSDate+WTF.h"

@implementation WatchViewCell{
    UILabel* _markTime;
    UIImageView* _imageView;
    UILabel* _teacherName;
    UILabel* _courseName;
    UILabel* _courseDiscrip;
    UILabel* _favoritNum;
    UILabel* _courseNum;
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) {
        return self;
    }
    self.accessoryType = UITableViewCellAccessoryNone;
    self.backgroundColor = nil;
    self.frame = AutoRectMake(0, 0, DEFAULT_WIDTH, 100, WTFAutoLayoutTypePic);
    
    _markTime = [[UILabel alloc] initWithFrame:AutoRectMake(10, 0, DEFAULT_WIDTH, 20, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_markTime];
    _markTime.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    
    _imageView = [[UIImageView alloc] initWithFrame:AutoRectMake(10, 30, 80, 60, WTFAutoLayoutTypeRaw)];
    _imageView.layer.cornerRadius = 18;
    _imageView.layer.masksToBounds = YES;
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_imageView];
    
    _teacherName = [[UILabel alloc]initWithFrame:AutoRectMake(100, 30, 200, 15, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_teacherName];
    _teacherName.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    
    _courseName = [[UILabel alloc]initWithFrame:AutoRectMake(100, 50, 200, 15, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_courseName];
    _courseName.font = [UIFont fontWithName:nil size:FONT_SIZE_TEXT_DEFAULT];
    
    _courseDiscrip = [[UILabel alloc]initWithFrame:AutoRectMake(100, 65, 200, 15, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_courseDiscrip];
    _courseDiscrip.font = [UIFont fontWithName:nil size:FONT_SIZE_TEXT_DEFAULT];
    
    _favoritNum = [[UILabel alloc]initWithFrame:AutoRectMake(100, 80, 100, 15, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_favoritNum];
    _favoritNum.font = [UIFont fontWithName:nil size:FONT_SIZE_TEXT_DEFAULT];
    
    //添加观看小图标
    UIImageView* watchImage = [[UIImageView alloc]initWithFrame:AutoRectMake(90, 82, 10, 10, WTFAutoLayoutTypeText)];
    [watchImage setImage:[UIImage imageNamed:@"collectionImage.jpg"]];
    [self.contentView addSubview:watchImage];
    
    //
    //添加收藏小图标
    UIImageView* collecTion = [[UIImageView alloc]initWithFrame:AutoRectMake(190, 82, 10, 10, WTFAutoLayoutTypeText)];
    [collecTion setImage:[UIImage imageNamed:@"watchImage.jpg"]];
    [self.contentView addSubview:collecTion];
    _courseNum = [[UILabel alloc]initWithFrame:AutoRectMake(200, 80, 100, 15, WTFAutoLayoutTypeText)];
    [self.contentView addSubview:_courseNum];
    _courseNum.font = [UIFont fontWithName:nil size:FONT_SIZE_TEXT_DEFAULT];
    
    return self;
}


-(void)setRecord:(WatchData* )record{
    _record = record;
    _markTime.text = _record.markDate;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_record.teacherHeadPhotoUrl]];
    _teacherName.text = _record.teacherName;
    _courseName.text = _record.courseName;
    _courseDiscrip.text = _record.courseDescription;
    _favoritNum.text = [NSString stringWithFormat:@"%d",[_record.favoritesNum intValue]];
    _courseNum.text = [NSString stringWithFormat:@"%d",[ _record.courseViewNum intValue]];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
